﻿using System;
using Microsoft.Practices.Prism.Commands;

namespace Present.Commands.Fluent
{
    public class DelegateCommandBuilder<T> : CommandBuilder<DelegateCommand<T>, T>
    {
        private Func<T, bool> canExecute = x => true;
        private Action<T> execute = x =>{};

        public DelegateCommandBuilder<T> CanExecuteIf(Func<T, bool> canExecuteAction)
        {
            this.canExecute = canExecuteAction;
            return this;
        }

        public DelegateCommandBuilder<T> Execute(Action<T> executeAction)
        {
            this.execute = executeAction;
            return this;
        }

        protected override DelegateCommand<T> BuildCommand()
        {
            return new DelegateCommand<T>(execute, canExecute);
        }

        public static implicit operator DelegateCommand<T>(DelegateCommandBuilder<T> builder)
        {
            return builder.BuildCommand();
        }
    }
}